package com.bestcem.xm.user.enums;

import com.bestcem.xm.user.constant.SmsConstant;
import com.bestcem.xm.user.util.business.StringFormatUtil;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;

import java.util.Map;
import java.util.stream.Stream;

/**
 * 限额通知用户事件枚举
 *
 * @author qiongyu.cui <qiongyu.cui@idiaoyan.com>
 * @version v1.0
 * @date 2022/7/14 16:51
 */
@Getter
@AllArgsConstructor
@NoArgsConstructor
public enum NotifyQuotaReachedEventEnum {

    /**
     * 限额通知用户事件枚举
     */
    PROJECT("project",
            EmailTemplateEnum.PROJECT_QUOTA_TEMPLATE.getFileName(),
            SmsConstant.PROJECT_QUOTA_SMS_TEMPLATE,
            "您正在使用的{pack_name}套餐可创建个{total_quota}问卷项目，当前{rate_str}，升级套餐以创建更多。",
            "问卷"),
    RSPD("rspd",
            EmailTemplateEnum.RSPD_QUOTA_TEMPLATE.getFileName(),
            SmsConstant.RSPD_QUOTA_SMS_TEMPLATE,
            "您正在使用的{pack_name}套餐可收集{total_quota}份答卷，当前{rate_str}，升级套餐以收集更多。",
            "答卷");

    /**
     * 事件类型
     */
    private String type;
    private String emailFileTemplateName;
    private String smsTemplate;
    private String answerQuotaTip;
    private String notifyTitle;

    /**
     * 根据type获取限额通知用户事件枚举
     *
     * @param type 事件类型
     * @return com.bestcem.xm.user.enums.NotifyQuotaReachedEventEnum
     * @author cuiqiongyu <qiongyu.cui@idiaoyan.cn>
     * @date 2022/07/14 17:07
     */
    public static NotifyQuotaReachedEventEnum getByType(String type) {
        return Stream.of(values()).filter(n -> n.type.equals(type)).findFirst().orElse(null);
    }

    /**
     * 获取answerQuotaTip的结果值
     *
     * @param param 参数
     * @return java.lang.String
     * @author cuiqiongyu <qiongyu.cui@idiaoyan.cn>
     * @date 2022/07/14 17:15
     */
    public String getAnswerQuotaTipResult(Map<String, Object> param) {
        return StringFormatUtil.format(answerQuotaTip, param);
    }

    /**
     * 获取smsTemplate的结果值
     *
     * @param param 参数
     * @return java.lang.String
     * @author cuiqiongyu <qiongyu.cui@idiaoyan.cn>
     * @date 2022/07/14 17:15
     */
    public String getSmsTemplateResult(Map<String, Object> param) {
        return StringFormatUtil.format(smsTemplate, param);
    }

}
